home *** CD-ROM | disk | FTP | other *** search
- PROGRAM ErrPatch;
-
- { The following INLINE MACRO allows a procedure or function to generate }
- { a runtime-error with the address of the CALLING statement. }
- { The ServiceRoutine must be FAR, otherwise the INLINE MACRO must be }
- { modified to POP the caller's IP from stack, PUSH CS and PUSH the IP }
- { again, as RunError expects a full SEGMENT:OFFSET address on stack }
-
- {NOV 18. 1988 , Per B. Larsen, Beta Computer Systems A/S, Frichsvej 40 }
- { DK 8600 Silkeborg, DENMARK, Voice + 45 6 82 61 00 }
- { Fax + 45 6 80 02 22, BBS +45 6 80 25 88 }
- { Telex 63203 PARNOR DK, CompuServe 75470,1320 }
-
- PROCEDURE RunErrorPatchToCaller;
- INLINE($89/$EC/ { MOV SP,BP Get rid of baseframe}
- $5D/ { POP BP for this routine }
- $E8/00/00/ { CALL LBL1 Only way to get IP }
- $5E/ {LBL1:POP SI into register }
- $83/$C6/$0F/ { ADD SI,15 Adjust to point to }
- { CALL RUNERROR instr.}
- $0E/ { PUSH CS Setup CODE SEGMENT }
- $07/ { POP ES addressability }
- $26/$C6/$04/$EA/ { MOV BYTE PTR ES:[SI],0EAh }
- { Modify CALL instr. }
- { generated by TURBO }
- { to JMP FAR instr. }
- $90/ { NOP Required to force }
- $90); { NOP read into CPU-cache }
- { AFTER patch }
-
- {Same as above, but reports the calling statement one level further up. }
- {You can expand the depth of "back-tracking" by copying the * marked }
- {lines the desired number of times. Remember all PROCs/FUNCs must be FAR}
- {Alternatively you could rewrite the MACRO to take the number of POP-OFF}
- {levels as a parameter.}
-
- PROCEDURE RunErrorPatchToCallerCaller;
- INLINE(
- $89/$EC/ { MOV SP,BP Get rid of baseframe }
- $5D/ { POP BP for this routine }
- $5E/ { POP SI Pop returnaddr * }
- $5E/ { POP SI for caller * }
- $89/$EC/ { MOV SP,BP Get rid of baseframe * }
- $5D/ { POP BP for previous routine * }
- $E8/00/00/ { CALL LBL1 Only way to get IP }
- $5E/ {LBL1:POP SI into register }
- $83/$C6/$0F/ { ADD SI,15 Adjust to point to }
- { CALL RUNERROR instr. }
- $0E/ { PUSH CS Setup CODE SEGMENT }
- $07/ { POP ES addressability }
- $26/$C6/$04/$EA/ { MOV BYTE PTR ES:[SI],0EAh }
- { Modify CALL instr. }
- { generated by TURBO }
- { to JMP FAR instr. }
- $90/ { NOP Required to force }
- $90); { NOP read into CPU-cache }
- { AFTER patch }
- PROCEDURE ServiceRoutine;
- BEGIN
- RunErrorPatchToCaller; {Do not put anything between this line and the
- next}
- RunError(255); {This instruction is patched by the previous
- line }
- END;
-
- PROCEDURE Caller;
- BEGIN
- ServiceRoutine;
- END;
-
- BEGIN
- Caller;
- END.